ARG P_V=8.1.33
FROM registry.cn-hangzhou.aliyuncs.com/xiaoyilin/php:${P_V} AS builder
LABEL author=xiaoyilin
LABEL email=406735078@qq.com
ARG S_V
ADD swoole-src-${S_V}.tar.gz  /usr/local/
WORKDIR /usr/local/swoole-src-${S_V}
RUN apt-get -y update && \
# 编译必需的软件包列表
apt-get -y install pkg-config autoconf build-essential libbrotli-dev && \
phpize && ./configure && make -j8 && make install
# 第二阶段
ARG P_V=8.1.33
FROM registry.cn-hangzhou.aliyuncs.com/xiaoyilin/php:${P_V}
LABEL author=xiaoyilin
LABEL email=406735078@qq.com
ENV TZ=Asia/Shanghai
ARG P_V
COPY --from=builder /usr/local/php${P_V} /usr/local/php${P_V}
WORKDIR /usr/local/php$P_V
RUN apt-get -y update && apt-get install -y libbrotli1 && \
sed -i '/zend_extension/a extension=swoole.so' lib/php.ini && \
rm -rf /var/lib/apt/lists/* && \
touch /usr/local/php$P_V/test.php && \
echo '<?php'>>/usr/local/php$P_V/test.php && \
echo '$http = new Swoole\Http\Server("0.0.0.0", 80);'>>/usr/local/php$P_V/test.php && \
echo "\$http->on('request', function (\$request, \$response) {">>/usr/local/php$P_V/test.php && \
echo '$response->end("<h1>Hello Swoole. #".rand(1000, 9999)."</h1>");'>>/usr/local/php$P_V/test.php && \
echo '});'>>/usr/local/php$P_V/test.php && \
echo '$http->start();'>>/usr/local/php$P_V/test.php && \
echo '?>'>>/usr/local/php$P_V/test.php
CMD ["php","test.php"]


# https://wiki.swoole.com/zh-cn/#/environment
# https://github.com/swoole/swoole-src/archive/refs/tags/v6.0.2.tar.gz
# docker build --build-arg S_V=6.0.2 --build-arg P_V=8.1.33 -t registry.cn-hangzhou.aliyuncs.com/xiaoyilin/swoole:6.0.2-php8.1 .
# docker build --build-arg S_V=6.0.2 --build-arg P_V=8.2.29 -t registry.cn-hangzhou.aliyuncs.com/xiaoyilin/swoole:6.0.2-php8.2 .
# docker build --build-arg S_V=6.0.2 --build-arg P_V=8.3.26 -t registry.cn-hangzhou.aliyuncs.com/xiaoyilin/swoole:6.0.2-php8.3 .
# docker build --build-arg S_V=6.0.2 --build-arg P_V=8.4.13 -t registry.cn-hangzhou.aliyuncs.com/xiaoyilin/swoole:6.0.2-php8.4 .
# docker run --rm registry.cn-hangzhou.aliyuncs.com/xiaoyilin/swoole:6.0.2-php8.1
# docker run -d -p 80:80 registry.cn-hangzhou.aliyuncs.com/xiaoyilin/swoole:6.0.2-php8.1
# docker run -p 80:80 -it --rm registry.cn-hangzhou.aliyuncs.com/xiaoyilin/swoole:6.0.2-php8.1 bash
# docker run -p 80:80 -it --rm -v /mnt/d/wsl/php-a/test.php:/usr/local/php8.1.33/test.php registry.cn-hangzhou.aliyuncs.com/xiaoyilin/swoole:6.0.2-php8.1 bash
# docker push registry.cn-hangzhou.aliyuncs.com/xiaoyilin/swoole:6.0.2-php8.1
# 启用Swoole扩展
# vim /usr/local/php8.1.33/lib/php.ini加入一行extension=swoole.so